//
//  VideoViewController.swift
//  Auscultation
//
//  Created by 张文博 on 2021/4/6.
//

import UIKit
import JXSegmentedView
class VideoViewController: BaseVC, UITextFieldDelegate {
    
    var dataSource = [VideoModel]()
    
    
    // MARK: - layout
    lazy var layout: UICollectionViewFlowLayout = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
        return layout
    }()
    lazy var collection: UICollectionView = {
        let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collection.showsHorizontalScrollIndicator = false
        collection.showsVerticalScrollIndicator = false
        collection.backgroundColor = .white
        collection.delegate = self
        collection.dataSource = self
        collection.register(UINib.init(nibName: "VideoViewCollectionViewCell", bundle: Bundle.main), forCellWithReuseIdentifier: "VideoViewCollectionViewCell")
        return collection
    }()


    override func viewDidLoad() {
        super.viewDidLoad()
        // 搜索 bar
        let search_bar = UIView.init()
        search_bar.backgroundColor = UIColor.white.withAlphaComponent(0.32)
        search_bar.layer.cornerRadius = 4
        search_bar.backgroundColor = UIColor.init(lgf_HexString: "F3F3F3")
        view.addSubview(search_bar)
        search_bar.snp.makeConstraints { (make) in
            make.top.equalTo(view).offset(20)
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(40)
        }
        let search_image = UIImageView()
        search_image.image = UIImage(named: "UIsheji_menjinxitong-17")
        search_bar.addSubview(search_image)
        search_image.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(12)
            make.width.height.equalTo(16)
        }
        let search_text = UITextField.init()
        search_text.attributedPlaceholder = NSAttributedString.init(string:"请输入您要搜索的视频内容", attributes: [NSAttributedString.Key.foregroundColor:UIColor.init(lgf_HexString: "A0A0A0")!])
        search_text.textColor = UIColor.black
        search_text.tintColor = UIColor.black
        search_text.font = UIFont.systemFont(ofSize: 12)
        search_text.delegate = self
        search_bar.addSubview(search_text)
        search_text.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(search_image.snp.right).offset(12)
            make.right.equalToSuperview().offset(-60)
            make.height.equalToSuperview()
        }
        
        let sx = UILabel.init()
        sx.text = "搜索"
        sx.font = UIFont.systemFont(ofSize: 14)
        sx.textAlignment = .center
        sx.textColor = UIColor.init(lgf_HexString: "A0A0A0")!
        sx.isUserInteractionEnabled = true
        sx.lgf_AddTap(target: self, action: #selector(VideoViewController.videoSearch(btn:)))
        view.addSubview(sx)
        sx.snp.makeConstraints { (make) in
            make.centerY.equalTo(search_bar)
            make.right.equalToSuperview().offset(-15)
            make.width.equalTo(50)
            make.height.equalTo(50)
        }
        
        let lineView = UIView()
        lineView.backgroundColor = UIColor.init(lgf_HexString: "A0A0A0")!
        view.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.right.equalTo(sx.snp.left)
            make.width.equalTo(1)
            make.height.equalTo(20)
            make.centerY.equalTo(search_bar)
        }
        view.addSubview(collection)
        collection.snp.makeConstraints { (make) in
            
            make.left.right.equalToSuperview()
            make.top.equalTo(search_bar.snp.bottom).offset(10)
            make.bottom.equalToSuperview().offset(-UIDevice.lgf_BottomSafeAreaH())
        }

    }
    
}

extension VideoViewController: JXSegmentedListContainerViewListDelegate {
    func listView() -> UIView {
        return view
    }
}

extension VideoViewController{
    
    @objc func videoSearch(btn:UIButton){
        
    }
}


extension VideoViewController:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
    
    // MARK: - UICollectionViewDataSource
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
      
        let cell = collectionView.lgf_DequeueReusableCell(with: VideoViewCollectionViewCell.self, for: indexPath)
        cell.iconImage.backgroundColor = .red

//        guard let model = studyDataArray[indexPath.item] else { return cell }
//        cell.model = model
        return cell
    }
    
    
    // MARK: - UICollectionViewDelegate
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
    }
    
    // MARK: - UICollectionViewDelegateFlowLayout
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        return CGSize(width: UIDevice.lgf_ScreenW, height: 250)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 15)
    }

}
